package activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.example.administrator.ci_edit.R;

import java.util.Random;

import entity.UserConfig;

/**
 * Created by mary on 2017/7/12.
 */

public class WelcomeActivity extends Activity {
    private final long DELAY_TIME = 3000;
    int count1;
    Random rand = new Random();
    private ImageView image;
    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        //欢迎界面（包括动画）
        image = (ImageView) findViewById(R.id.image);
        int a = rand.nextInt(7) + 1;
        String resultStr = "a" + a;
        int resId = getResources().getIdentifier(resultStr, "drawable", getPackageName());
        image.setBackgroundResource(resId);
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.enlarge);
        animation.setFillAfter(true);
        image.startAnimation(animation);
//        //加intent
//        Intent intent=new Intent(WelcomeActivity.this, SupperActivity.class);
//        startActivity(intent);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                sharedPreferences = getSharedPreferences("userInfo", Context.MODE_PRIVATE);


                Intent intent;
                if (sharedPreferences.getBoolean("isFirst", true)) {
                    //intent = new Intent(WelcomeActivity.this, SupperActivity.class);

                    intent = new Intent(WelcomeActivity.this, GuideActivity.class);
                    Log.d("", "运行完了");
                    //intent = new Intent(WelcomeActivity.this, LoginActivity.class);
                } else if (!sharedPreferences.getBoolean("isLogin", false)) {
                    Log.d("isLogin", "false");
                    UserConfig.setIslogin(false);
                    intent = new Intent(WelcomeActivity.this, LoginActivity.class);
                } else {
                    Log.d("isLogin", "true");
                    UserConfig.setIslogin(true);
                    intent = new Intent(WelcomeActivity.this, SupperActivity.class);
                }
                startActivity(intent);
                finish();//一finish就出错
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
//        判断是否需要引导界面
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    Thread.sleep(3000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//
//            }
//        });
    }
}





